default: show_config test_default test_norun

##  VERILATOR_ROOT is where the verilator is installed.
VERILATOR_ROOT := /home/jian/Projects/verilator
export VERILATOR_ROOT

include $(VERILATOR_ROOT)/include/verilated.mk

DEBUG_QUIET = --debug --debugi 0 --gdbbt --no-dump-tree
DEBUG_ON = --debug --trace-dups --gdbbt
VALGRIND_ON = $(DEBUG_ON) --gdb "valgrind -v --leak-check=yes"

test_default: prep compile run
test_debug: prep_dbg compile run
test_valgrind: prep_vg compile run
test_norun: prep compile

VERILATOR_FLAGS = --cc -f $(VERILATOR_ROOT)/test_v/input.vc top.v
VERILATOR_FLAGS += --trace

show_config:
	$(PERL) $(VERILATOR_ROOT)/bin/verilator $(DEBUG_QUIET) -V
prep:
	$(PERL) $(VERILATOR_ROOT)/bin/verilator $(DEBUG_QUIET) $(VERILATOR_FLAGS)
prep_dbg:
	$(PERL) $(VERILATOR_ROOT)/bin/verilator $(DEBUG_ON) $(VERILATOR_FLAGS)
prep_vg:
	$(PERL) $(VERILATOR_ROOT)/bin/verilator $(VALGRIND_ON) $(VERILATOR_FLAGS)
compile:
	cd obj_dir; $(MAKE) -j 3 -f ../Makefile_obj
run:
	obj_dir/simx
obj_dir:
	mkdir $@

maintainer_copy::
clean mostlyclean distclean maintainer_clean:
	-rm -rf obj_dir *.log *.dmp *.vpd core

